package cn.yomigaeri.common.result;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @ClassName: Result
 * @Package: cn.yomigaeri.common.result
 * @Description:
 * @Author Yomigaeri
 * @Create 2025/6/4 16:03
 * @Version 1.0
 */
@Data
@NoArgsConstructor
public class Result<T> implements Serializable {
    private Integer code; //编码：1成功，0和其它数字为失败
    private String msg; //错误信息
    private T data; //数据

    public Result(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(1, "success", data);
    }

    public static <T> Result<T> error(String msg) {
        return new Result<>(0, msg, null);
    }

    public static <T> Result<T> success() {
        return new Result<>(1, "success", null);
    }
}
